home *** CD-ROM | disk | FTP | other *** search
/ Transformers: Revenge of …he Game: Press Kit (USA) / Transformers - Revenge of the Fallen - The Game - Press Kit (USA).bin / Transformers.swf / scripts / fl / video / VideoPlayer.as < prev    next >
Text File  |  2009-06-19  |  82KB  |  2,390 lines

  1. package fl.video
  2. {
  3.    import flash.events.NetStatusEvent;
  4.    import flash.events.TimerEvent;
  5.    import flash.geom.Rectangle;
  6.    import flash.media.SoundTransform;
  7.    import flash.media.Video;
  8.    import flash.net.NetConnection;
  9.    import flash.net.NetStream;
  10.    import flash.utils.Timer;
  11.    import flash.utils.getDefinitionByName;
  12.    import flash.utils.getTimer;
  13.    
  14.    use namespace flvplayback_internal;
  15.    
  16.    public class VideoPlayer extends Video
  17.    {
  18.       
  19.       public static var netStreamClientClass:Object = VideoPlayerClient;
  20.       
  21.       public static var iNCManagerClass:Object = "fl.video.NCManager";
  22.       
  23.       flvplayback_internal static const FINISH_AUTO_RESIZE_INTERVAL:Number = 250;
  24.       
  25.       flvplayback_internal static const DEFAULT_AUTO_RESIZE_PLAYHEAD_TIMEOUT:Number = 0.5;
  26.       
  27.       flvplayback_internal static const DEFAULT_AUTO_RESIZE_METADATA_DELAY_MAX:Number = 5;
  28.       
  29.       public static const SHORT_VERSION:String = "2.1";
  30.       
  31.       flvplayback_internal static const HTTP_DO_SEEK_INTERVAL:Number = 250;
  32.       
  33.       flvplayback_internal static const DEFAULT_HTTP_DO_SEEK_MAX_COUNT:Number = 4;
  34.       
  35.       flvplayback_internal static const RTMP_DO_SEEK_INTERVAL:Number = 100;
  36.       
  37.       flvplayback_internal static const HTTP_DELAYED_BUFFERING_INTERVAL:Number = 100;
  38.       
  39.       public static const DEFAULT_UPDATE_TIME_INTERVAL:Number = 250;
  40.       
  41.       flvplayback_internal static var BUFFER_FLUSH:String = "bufferFlush";
  42.       
  43.       flvplayback_internal static var BUFFER_FULL:String = "bufferFull";
  44.       
  45.       flvplayback_internal static const AUTO_RESIZE_INTERVAL:Number = 100;
  46.       
  47.       public static const DEFAULT_IDLE_TIMEOUT_INTERVAL:Number = 300000;
  48.       
  49.       flvplayback_internal static const DEFAULT_LAST_UPDATE_TIME_STUCK_COUNT_MAX:int = 10;
  50.       
  51.       flvplayback_internal static const RTMP_DO_STOP_AT_END_INTERVAL:Number = 500;
  52.       
  53.       flvplayback_internal static var BUFFER_EMPTY:String = "bufferEmpty";
  54.       
  55.       public static const VERSION:String = "2.1.0.19";
  56.       
  57.       public static const DEFAULT_UPDATE_PROGRESS_INTERVAL:Number = 250;
  58.        
  59.       
  60.       protected var _align:String;
  61.       
  62.       protected var _registrationWidth:Number;
  63.       
  64.       flvplayback_internal var _updateProgressTimer:Timer;
  65.       
  66.       flvplayback_internal var _atEndCheckPlayhead:Number;
  67.       
  68.       flvplayback_internal var _hiddenForResize:Boolean;
  69.       
  70.       flvplayback_internal var startProgressTime:Number;
  71.       
  72.       protected var _volume:Number;
  73.       
  74.       flvplayback_internal var _invalidSeekTime:Boolean;
  75.       
  76.       protected var _isLive:Boolean;
  77.       
  78.       flvplayback_internal var _readyDispatched:Boolean;
  79.       
  80.       flvplayback_internal var lastUpdateTimeStuckCount:Number;
  81.       
  82.       protected var _ns:NetStream;
  83.       
  84.       protected var _streamLength:Number;
  85.       
  86.       flvplayback_internal var _bufferState:String;
  87.       
  88.       flvplayback_internal var _rtmpDoSeekTimer:Timer;
  89.       
  90.       flvplayback_internal var lastUpdateTimeStuckCountMax:int = 10;
  91.       
  92.       protected var _contentPath:String;
  93.       
  94.       flvplayback_internal var _lastUpdateTime:Number;
  95.       
  96.       protected var _metadata:Object;
  97.       
  98.       protected var __visible:Boolean;
  99.       
  100.       flvplayback_internal var autoResizeMetadataDelayMax:Number = 5;
  101.       
  102.       protected var _scaleMode:String;
  103.       
  104.       flvplayback_internal var _sawPlayStop:Boolean;
  105.       
  106.       flvplayback_internal var _atEnd:Boolean;
  107.       
  108.       flvplayback_internal var _sawSeekNotify:Boolean;
  109.       
  110.       flvplayback_internal var _idleTimeoutTimer:Timer;
  111.       
  112.       flvplayback_internal var _prevVideoWidth:int;
  113.       
  114.       protected var _registrationX:Number;
  115.       
  116.       protected var _registrationY:Number;
  117.       
  118.       protected var _bufferTime:Number;
  119.       
  120.       flvplayback_internal var _cachedState:String;
  121.       
  122.       flvplayback_internal var totalDownloadTime:Number;
  123.       
  124.       flvplayback_internal var _cachedPlayheadTime:Number;
  125.       
  126.       protected var _autoPlay:Boolean;
  127.       
  128.       protected var _autoRewind:Boolean;
  129.       
  130.       flvplayback_internal var _invalidSeekRecovery:Boolean;
  131.       
  132.       flvplayback_internal var _hiddenRewindPlayheadTime:Number;
  133.       
  134.       flvplayback_internal var _prevVideoHeight:int;
  135.       
  136.       protected var _ncMgr:INCManager;
  137.       
  138.       protected var _soundTransform:SoundTransform;
  139.       
  140.       flvplayback_internal var _httpDoSeekCount:Number;
  141.       
  142.       flvplayback_internal var oldRegistrationBounds:Rectangle;
  143.       
  144.       flvplayback_internal var _cmdQueue:Array;
  145.       
  146.       flvplayback_internal var _updateTimeTimer:Timer;
  147.       
  148.       flvplayback_internal var _startingPlay:Boolean;
  149.       
  150.       flvplayback_internal var httpDoSeekMaxCount:Number = 4;
  151.       
  152.       flvplayback_internal var _httpDoSeekTimer:Timer;
  153.       
  154.       flvplayback_internal var baselineProgressTime:Number;
  155.       
  156.       flvplayback_internal var _autoResizeTimer:Timer;
  157.       
  158.       flvplayback_internal var _autoResizeDone:Boolean;
  159.       
  160.       protected var _state:String;
  161.       
  162.       protected var _videoWidth:int;
  163.       
  164.       flvplayback_internal var _finishAutoResizeTimer:Timer;
  165.       
  166.       flvplayback_internal var _resizeImmediatelyOnMetadata:Boolean;
  167.       
  168.       flvplayback_internal var _currentPos:Number;
  169.       
  170.       flvplayback_internal var oldBounds:Rectangle;
  171.       
  172.       protected var _videoHeight:int;
  173.       
  174.       flvplayback_internal var _delayedBufferingTimer:Timer;
  175.       
  176.       flvplayback_internal var waitingForEnough:Boolean;
  177.       
  178.       flvplayback_internal var _hiddenForResizeMetadataDelay:Number;
  179.       
  180.       protected var _registrationHeight:Number;
  181.       
  182.       flvplayback_internal var autoResizePlayheadTimeout:Number = 0.5;
  183.       
  184.       flvplayback_internal var _rtmpDoStopAtEndTimer:Timer;
  185.       
  186.       flvplayback_internal var _lastSeekTime:Number;
  187.       
  188.       flvplayback_internal var totalProgressTime:Number;
  189.       
  190.       public function VideoPlayer(param1:int = 320, param2:int = 240)
  191.       {
  192.          super(param1,param2);
  193.          _registrationX = x;
  194.          _registrationY = y;
  195.          _registrationWidth = param1;
  196.          _registrationHeight = param2;
  197.          _state = VideoState.DISCONNECTED;
  198.          _cachedState = _state;
  199.          _bufferState = flvplayback_internal::BUFFER_EMPTY;
  200.          _sawPlayStop = false;
  201.          _cachedPlayheadTime = 0;
  202.          _metadata = null;
  203.          _startingPlay = false;
  204.          _invalidSeekTime = false;
  205.          _invalidSeekRecovery = false;
  206.          _currentPos = 0;
  207.          _atEnd = false;
  208.          _streamLength = 0;
  209.          _cmdQueue = new Array();
  210.          _readyDispatched = false;
  211.          _autoResizeDone = false;
  212.          _lastUpdateTime = NaN;
  213.          lastUpdateTimeStuckCount = 0;
  214.          _sawSeekNotify = false;
  215.          _hiddenForResize = false;
  216.          _hiddenForResizeMetadataDelay = 0;
  217.          _resizeImmediatelyOnMetadata = false;
  218.          _videoWidth = -1;
  219.          _videoHeight = -1;
  220.          _prevVideoWidth = 0;
  221.          _prevVideoHeight = 0;
  222.          _updateTimeTimer = new Timer(DEFAULT_UPDATE_TIME_INTERVAL);
  223.          flvplayback_internal::_updateTimeTimer.addEventListener(TimerEvent.TIMER,flvplayback_internal::doUpdateTime);
  224.          _updateProgressTimer = new Timer(DEFAULT_UPDATE_PROGRESS_INTERVAL);
  225.          flvplayback_internal::_updateProgressTimer.addEventListener(TimerEvent.TIMER,flvplayback_internal::doUpdateProgress);
  226.          _idleTimeoutTimer = new Timer(DEFAULT_IDLE_TIMEOUT_INTERVAL,1);
  227.          flvplayback_internal::_idleTimeoutTimer.addEventListener(TimerEvent.TIMER,flvplayback_internal::doIdleTimeout);
  228.          _autoResizeTimer = new Timer(flvplayback_internal::AUTO_RESIZE_INTERVAL);
  229.          flvplayback_internal::_autoResizeTimer.addEventListener(TimerEvent.TIMER,flvplayback_internal::doAutoResize);
  230.          _rtmpDoStopAtEndTimer = new Timer(flvplayback_internal::RTMP_DO_STOP_AT_END_INTERVAL);
  231.          flvplayback_internal::_rtmpDoStopAtEndTimer.addEventListener(TimerEvent.TIMER,flvplayback_internal::rtmpDoStopAtEnd);
  232.          _rtmpDoSeekTimer = new Timer(flvplayback_internal::RTMP_DO_SEEK_INTERVAL);
  233.          flvplayback_internal::_rtmpDoSeekTimer.addEventListener(TimerEvent.TIMER,flvplayback_internal::rtmpDoSeek);
  234.          _httpDoSeekTimer = new Timer(flvplayback_internal::HTTP_DO_SEEK_INTERVAL);
  235.          flvplayback_internal::_httpDoSeekTimer.addEventListener(TimerEvent.TIMER,flvplayback_internal::httpDoSeek);
  236.          _httpDoSeekCount = 0;
  237.          _finishAutoResizeTimer = new Timer(flvplayback_internal::FINISH_AUTO_RESIZE_INTERVAL,1);
  238.          flvplayback_internal::_finishAutoResizeTimer.addEventListener(TimerEvent.TIMER,flvplayback_internal::finishAutoResize);
  239.          _delayedBufferingTimer = new Timer(flvplayback_internal::HTTP_DELAYED_BUFFERING_INTERVAL);
  240.          flvplayback_internal::_delayedBufferingTimer.addEventListener(TimerEvent.TIMER,flvplayback_internal::doDelayedBuffering);
  241.          _isLive = false;
  242.          _align = VideoAlign.CENTER;
  243.          _scaleMode = VideoScaleMode.MAINTAIN_ASPECT_RATIO;
  244.          _autoPlay = true;
  245.          _autoRewind = false;
  246.          _bufferTime = 0.1;
  247.          _soundTransform = new SoundTransform();
  248.          _volume = _soundTransform.volume;
  249.          __visible = true;
  250.          _contentPath = "";
  251.          waitingForEnough = false;
  252.          baselineProgressTime = NaN;
  253.          startProgressTime = NaN;
  254.          totalDownloadTime = NaN;
  255.          totalProgressTime = NaN;
  256.       }
  257.       
  258.       public function get playheadTime() : Number
  259.       {
  260.          var _loc1_:Number = _ns == null ? Number(flvplayback_internal::_currentPos) : Number(_ns.time);
  261.          if(_metadata != null && _metadata.audiodelay != undefined)
  262.          {
  263.             _loc1_ -= _metadata.audiodelay;
  264.             if(_loc1_ < 0)
  265.             {
  266.                _loc1_ = 0;
  267.             }
  268.          }
  269.          return _loc1_;
  270.       }
  271.       
  272.       public function stop() : void
  273.       {
  274.          if(!isXnOK())
  275.          {
  276.             if(_state == VideoState.CONNECTION_ERROR || _ncMgr == null || _ncMgr.netConnection == null)
  277.             {
  278.                throw new VideoError(VideoError.NO_CONNECTION);
  279.             }
  280.             return;
  281.          }
  282.          if(_state == VideoState.EXEC_QUEUED_CMD)
  283.          {
  284.             _state = flvplayback_internal::_cachedState;
  285.          }
  286.          else
  287.          {
  288.             if(!stateResponsive)
  289.             {
  290.                queueCmd(QueuedCommand.STOP);
  291.                return;
  292.             }
  293.             execQueuedCmds();
  294.          }
  295.          if(_state == VideoState.STOPPED || _ns == null)
  296.          {
  297.             return;
  298.          }
  299.          if(_ncMgr.isRTMP)
  300.          {
  301.             if(_autoRewind && !_isLive)
  302.             {
  303.                _currentPos = 0;
  304.                _play(0,0);
  305.                _state = VideoState.STOPPED;
  306.                setState(VideoState.REWINDING);
  307.             }
  308.             else
  309.             {
  310.                closeNS(true);
  311.                setState(VideoState.STOPPED);
  312.             }
  313.          }
  314.          else
  315.          {
  316.             _pause(true);
  317.             if(_autoRewind)
  318.             {
  319.                _seek(0);
  320.                _state = VideoState.STOPPED;
  321.                setState(VideoState.REWINDING);
  322.             }
  323.             else
  324.             {
  325.                setState(VideoState.STOPPED);
  326.             }
  327.          }
  328.       }
  329.       
  330.       public function setScale(param1:Number, param2:Number) : void
  331.       {
  332.          super.scaleX = param1;
  333.          super.scaleY = param2;
  334.          _registrationWidth = width;
  335.          _registrationHeight = height;
  336.          switch(_scaleMode)
  337.          {
  338.             case VideoScaleMode.MAINTAIN_ASPECT_RATIO:
  339.             case VideoScaleMode.NO_SCALE:
  340.                startAutoResize();
  341.                break;
  342.             default:
  343.                super.x = _registrationX;
  344.                super.y = _registrationY;
  345.          }
  346.       }
  347.       
  348.       public function set playheadTime(param1:Number) : void
  349.       {
  350.          seek(param1);
  351.       }
  352.       
  353.       override public function get videoWidth() : int
  354.       {
  355.          if(_videoWidth > 0)
  356.          {
  357.             return _videoWidth;
  358.          }
  359.          if(_metadata != null && !isNaN(_metadata.width) && !isNaN(_metadata.height))
  360.          {
  361.             if(_metadata.width == _metadata.height && flvplayback_internal::_readyDispatched)
  362.             {
  363.                return super.videoWidth;
  364.             }
  365.             return int(_metadata.width);
  366.          }
  367.          if(flvplayback_internal::_readyDispatched)
  368.          {
  369.             return super.videoWidth;
  370.          }
  371.          return -1;
  372.       }
  373.       
  374.       public function get scaleMode() : String
  375.       {
  376.          return _scaleMode;
  377.       }
  378.       
  379.       public function get progressInterval() : Number
  380.       {
  381.          return flvplayback_internal::_updateProgressTimer.delay;
  382.       }
  383.       
  384.       public function set align(param1:String) : void
  385.       {
  386.          if(_align != param1)
  387.          {
  388.             switch(param1)
  389.             {
  390.                case VideoAlign.CENTER:
  391.                case VideoAlign.TOP:
  392.                case VideoAlign.LEFT:
  393.                case VideoAlign.BOTTOM:
  394.                case VideoAlign.RIGHT:
  395.                case VideoAlign.TOP_LEFT:
  396.                case VideoAlign.TOP_RIGHT:
  397.                case VideoAlign.BOTTOM_LEFT:
  398.                case VideoAlign.BOTTOM_RIGHT:
  399.                   _align = param1;
  400.                   switch(_scaleMode)
  401.                   {
  402.                      case VideoScaleMode.MAINTAIN_ASPECT_RATIO:
  403.                      case VideoScaleMode.NO_SCALE:
  404.                         startAutoResize();
  405.                   }
  406.                   break;
  407.                default:
  408.                   return;
  409.             }
  410.          }
  411.       }
  412.       
  413.       public function set scaleMode(param1:String) : void
  414.       {
  415.          if(_scaleMode != param1)
  416.          {
  417.             switch(param1)
  418.             {
  419.                case VideoScaleMode.MAINTAIN_ASPECT_RATIO:
  420.                case VideoScaleMode.NO_SCALE:
  421.                case VideoScaleMode.EXACT_FIT:
  422.                   if(_scaleMode == VideoScaleMode.EXACT_FIT && flvplayback_internal::_resizeImmediatelyOnMetadata && (_videoWidth < 0 || _videoHeight < 0))
  423.                   {
  424.                      _resizeImmediatelyOnMetadata = false;
  425.                   }
  426.                   _scaleMode = param1;
  427.                   startAutoResize();
  428.                   break;
  429.                default:
  430.                   return;
  431.             }
  432.          }
  433.       }
  434.       
  435.       public function get source() : String
  436.       {
  437.          return _contentPath;
  438.       }
  439.       
  440.       flvplayback_internal function doUpdateTime(param1:TimerEvent = null) : void
  441.       {
  442.          var _loc2_:Number = playheadTime;
  443.          if(_loc2_ != flvplayback_internal::_atEndCheckPlayhead)
  444.          {
  445.             _atEndCheckPlayhead = NaN;
  446.          }
  447.          switch(_state)
  448.          {
  449.             case VideoState.STOPPED:
  450.             case VideoState.PAUSED:
  451.             case VideoState.DISCONNECTED:
  452.             case VideoState.CONNECTION_ERROR:
  453.                flvplayback_internal::_updateTimeTimer.stop();
  454.                break;
  455.             case VideoState.PLAYING:
  456.             case VideoState.BUFFERING:
  457.                if(_ncMgr != null && !_ncMgr.isRTMP && flvplayback_internal::_lastUpdateTime == _loc2_ && _ns != null && _ns.bytesLoaded == _ns.bytesTotal)
  458.                {
  459.                   if(flvplayback_internal::lastUpdateTimeStuckCount > flvplayback_internal::lastUpdateTimeStuckCountMax)
  460.                   {
  461.                      lastUpdateTimeStuckCount = 0;
  462.                      httpDoStopAtEnd();
  463.                   }
  464.                   else
  465.                   {
  466.                      ++lastUpdateTimeStuckCount;
  467.                   }
  468.                }
  469.          }
  470.          if(flvplayback_internal::_lastUpdateTime != _loc2_)
  471.          {
  472.             dispatchEvent(new VideoEvent(VideoEvent.PLAYHEAD_UPDATE,false,false,_state,_loc2_));
  473.             _lastUpdateTime = _loc2_;
  474.             lastUpdateTimeStuckCount = 0;
  475.          }
  476.       }
  477.       
  478.       flvplayback_internal function rtmpNetStatus(param1:NetStatusEvent) : void
  479.       {
  480.          if(_state == VideoState.CONNECTION_ERROR)
  481.          {
  482.             return;
  483.          }
  484.          switch(param1.info.code)
  485.          {
  486.             case "NetStream.Play.Stop":
  487.                if(flvplayback_internal::_startingPlay)
  488.                {
  489.                   return;
  490.                }
  491.                switch(_state)
  492.                {
  493.                   case VideoState.RESIZING:
  494.                      if(flvplayback_internal::_hiddenForResize)
  495.                      {
  496.                         finishAutoResize();
  497.                      }
  498.                      break;
  499.                   case VideoState.LOADING:
  500.                   case VideoState.STOPPED:
  501.                   case VideoState.PAUSED:
  502.                      break;
  503.                   default:
  504.                      _sawPlayStop = true;
  505.                      if(!flvplayback_internal::_rtmpDoStopAtEndTimer.running && (flvplayback_internal::_bufferState == flvplayback_internal::BUFFER_FLUSH || _ns.bufferTime <= 0.1 && _ns.bufferLength <= 0.1))
  506.                      {
  507.                         _cachedPlayheadTime = playheadTime;
  508.                         flvplayback_internal::_rtmpDoStopAtEndTimer.reset();
  509.                         flvplayback_internal::_rtmpDoStopAtEndTimer.start();
  510.                      }
  511.                }
  512.                break;
  513.             case "NetStream.Buffer.Empty":
  514.                switch(flvplayback_internal::_bufferState)
  515.                {
  516.                   case flvplayback_internal::BUFFER_FULL:
  517.                      if(flvplayback_internal::_sawPlayStop)
  518.                      {
  519.                         rtmpDoStopAtEnd();
  520.                      }
  521.                      else if(_state == VideoState.PLAYING)
  522.                      {
  523.                         setState(VideoState.BUFFERING);
  524.                      }
  525.                }
  526.                _bufferState = flvplayback_internal::BUFFER_EMPTY;
  527.                _sawPlayStop = false;
  528.                break;
  529.             case "NetStream.Buffer.Flush":
  530.                if(flvplayback_internal::_sawSeekNotify && _state == VideoState.SEEKING)
  531.                {
  532.                   _bufferState = flvplayback_internal::BUFFER_EMPTY;
  533.                   _sawPlayStop = false;
  534.                   setStateFromCachedState(false);
  535.                   doUpdateTime();
  536.                   execQueuedCmds();
  537.                }
  538.                if(!flvplayback_internal::_rtmpDoStopAtEndTimer.running && flvplayback_internal::_sawPlayStop && (flvplayback_internal::_bufferState == flvplayback_internal::BUFFER_EMPTY || _ns.bufferTime <= 0.1 && _ns.bufferLength <= 0.1))
  539.                {
  540.                   _cachedPlayheadTime = playheadTime;
  541.                   flvplayback_internal::_rtmpDoStopAtEndTimer.reset();
  542.                   flvplayback_internal::_rtmpDoStopAtEndTimer.start();
  543.                }
  544.                switch(flvplayback_internal::_bufferState)
  545.                {
  546.                   case flvplayback_internal::BUFFER_EMPTY:
  547.                      if(!flvplayback_internal::_hiddenForResize)
  548.                      {
  549.                         if(_state == VideoState.LOADING && flvplayback_internal::_cachedState == VideoState.PLAYING || _state == VideoState.BUFFERING)
  550.                         {
  551.                            setState(VideoState.PLAYING);
  552.                         }
  553.                         else if(flvplayback_internal::_cachedState == VideoState.BUFFERING)
  554.                         {
  555.                            _cachedState = VideoState.PLAYING;
  556.                         }
  557.                      }
  558.                      _bufferState = flvplayback_internal::BUFFER_FLUSH;
  559.                      break;
  560.                   default:
  561.                      if(_state == VideoState.BUFFERING)
  562.                      {
  563.                         setStateFromCachedState();
  564.                      }
  565.                }
  566.                break;
  567.             case "NetStream.Buffer.Full":
  568.                if(flvplayback_internal::_sawSeekNotify && _state == VideoState.SEEKING)
  569.                {
  570.                   _bufferState = flvplayback_internal::BUFFER_EMPTY;
  571.                   _sawPlayStop = false;
  572.                   setStateFromCachedState(false);
  573.                   doUpdateTime();
  574.                   execQueuedCmds();
  575.                }
  576.                switch(flvplayback_internal::_bufferState)
  577.                {
  578.                   case flvplayback_internal::BUFFER_EMPTY:
  579.                      _bufferState = flvplayback_internal::BUFFER_FULL;
  580.                      if(!flvplayback_internal::_hiddenForResize)
  581.                      {
  582.                         if(_state == VideoState.LOADING && flvplayback_internal::_cachedState == VideoState.PLAYING || _state == VideoState.BUFFERING)
  583.                         {
  584.                            setState(VideoState.PLAYING);
  585.                         }
  586.                         else if(flvplayback_internal::_cachedState == VideoState.BUFFERING)
  587.                         {
  588.                            _cachedState = VideoState.PLAYING;
  589.                         }
  590.                         if(flvplayback_internal::_rtmpDoStopAtEndTimer.running)
  591.                         {
  592.                            _sawPlayStop = true;
  593.                            flvplayback_internal::_rtmpDoStopAtEndTimer.reset();
  594.                         }
  595.                      }
  596.                      break;
  597.                   case flvplayback_internal::BUFFER_FLUSH:
  598.                      _bufferState = flvplayback_internal::BUFFER_FULL;
  599.                      if(flvplayback_internal::_rtmpDoStopAtEndTimer.running)
  600.                      {
  601.                         _sawPlayStop = true;
  602.                         flvplayback_internal::_rtmpDoStopAtEndTimer.reset();
  603.                      }
  604.                }
  605.                if(_state == VideoState.BUFFERING)
  606.                {
  607.                   setStateFromCachedState();
  608.                }
  609.                break;
  610.             case "NetStream.Pause.Notify":
  611.                if(_state == VideoState.RESIZING && flvplayback_internal::_hiddenForResize)
  612.                {
  613.                   finishAutoResize();
  614.                }
  615.                break;
  616.             case "NetStream.Unpause.Notify":
  617.                if(_state == VideoState.PAUSED)
  618.                {
  619.                   _state = VideoState.PLAYING;
  620.                   setState(VideoState.BUFFERING);
  621.                }
  622.                else
  623.                {
  624.                   _cachedState = VideoState.PLAYING;
  625.                }
  626.                break;
  627.             case "NetStream.Play.Start":
  628.                flvplayback_internal::_rtmpDoStopAtEndTimer.reset();
  629.                _bufferState = flvplayback_internal::BUFFER_EMPTY;
  630.                _sawPlayStop = false;
  631.                if(flvplayback_internal::_startingPlay)
  632.                {
  633.                   _startingPlay = false;
  634.                   _cachedPlayheadTime = playheadTime;
  635.                }
  636.                else if(_state == VideoState.PLAYING)
  637.                {
  638.                   setState(VideoState.BUFFERING);
  639.                }
  640.                break;
  641.             case "NetStream.Play.Reset":
  642.                flvplayback_internal::_rtmpDoStopAtEndTimer.reset();
  643.                if(_state == VideoState.REWINDING)
  644.                {
  645.                   flvplayback_internal::_rtmpDoSeekTimer.reset();
  646.                   if(playheadTime == 0 || playheadTime < flvplayback_internal::_cachedPlayheadTime)
  647.                   {
  648.                      setStateFromCachedState();
  649.                   }
  650.                   else
  651.                   {
  652.                      _cachedPlayheadTime = playheadTime;
  653.                      flvplayback_internal::_rtmpDoSeekTimer.start();
  654.                   }
  655.                }
  656.                break;
  657.             case "NetStream.Seek.Notify":
  658.                if(playheadTime != flvplayback_internal::_cachedPlayheadTime)
  659.                {
  660.                   setStateFromCachedState(false);
  661.                   doUpdateTime();
  662.                   execQueuedCmds();
  663.                }
  664.                else
  665.                {
  666.                   _sawSeekNotify = true;
  667.                   flvplayback_internal::_rtmpDoSeekTimer.start();
  668.                }
  669.                break;
  670.             case "Netstream.Play.UnpublishNotify":
  671.                break;
  672.             case "Netstream.Play.PublishNotify":
  673.                break;
  674.             case "NetStream.Play.StreamNotFound":
  675.                closeNS(false);
  676.                if(!_ncMgr.connectAgain())
  677.                {
  678.                   setState(VideoState.CONNECTION_ERROR);
  679.                }
  680.                break;
  681.             case "NetStream.Play.Failed":
  682.             case "NetStream.Failed":
  683.             case "NetStream.Play.FileStructureInvalid":
  684.             case "NetStream.Play.NoSupportedTrackFound":
  685.                setState(VideoState.CONNECTION_ERROR);
  686.          }
  687.       }
  688.       
  689.       public function get ncMgr() : INCManager
  690.       {
  691.          if(_ncMgr == null)
  692.          {
  693.             createINCManager();
  694.          }
  695.          return _ncMgr;
  696.       }
  697.       
  698.       public function set progressInterval(param1:Number) : void
  699.       {
  700.          flvplayback_internal::_updateProgressTimer.delay = param1;
  701.       }
  702.       
  703.       flvplayback_internal function createINCManager() : void
  704.       {
  705.          var theClass:Class = null;
  706.          try
  707.          {
  708.             if(iNCManagerClass is String)
  709.             {
  710.                theClass = Class(getDefinitionByName(String(iNCManagerClass)));
  711.             }
  712.             else if(iNCManagerClass is Class)
  713.             {
  714.                theClass = Class(iNCManagerClass);
  715.             }
  716.          }
  717.          catch(e:Error)
  718.          {
  719.             theClass = null;
  720.          }
  721.          if(theClass == null)
  722.          {
  723.             throw new VideoError(VideoError.INCMANAGER_CLASS_UNSET,iNCManagerClass == null ? "null" : iNCManagerClass.toString());
  724.          }
  725.          _ncMgr = new theClass();
  726.          _ncMgr.videoPlayer = this;
  727.       }
  728.       
  729.       flvplayback_internal function doAutoResize(param1:TimerEvent = null) : void
  730.       {
  731.          var _loc3_:int = 0;
  732.          var _loc4_:int = 0;
  733.          var _loc5_:Number = NaN;
  734.          var _loc6_:Number = NaN;
  735.          if(flvplayback_internal::_autoResizeTimer.running)
  736.          {
  737.             switch(_state)
  738.             {
  739.                case VideoState.RESIZING:
  740.                case VideoState.LOADING:
  741.                   break;
  742.                case VideoState.DISCONNECTED:
  743.                case VideoState.CONNECTION_ERROR:
  744.                   flvplayback_internal::_autoResizeTimer.reset();
  745.                   return;
  746.                default:
  747.                   if(!stateResponsive)
  748.                   {
  749.                      return;
  750.                   }
  751.                   break;
  752.             }
  753.             if(!(super.videoWidth != flvplayback_internal::_prevVideoWidth || super.videoHeight != flvplayback_internal::_prevVideoHeight || flvplayback_internal::_bufferState == flvplayback_internal::BUFFER_FULL || flvplayback_internal::_bufferState == flvplayback_internal::BUFFER_FLUSH || _ns.time > flvplayback_internal::autoResizePlayheadTimeout))
  754.             {
  755.                return;
  756.             }
  757.             if(flvplayback_internal::_hiddenForResize && !_ns.client.ready && flvplayback_internal::_hiddenForResizeMetadataDelay < flvplayback_internal::autoResizeMetadataDelayMax)
  758.             {
  759.                ++_hiddenForResizeMetadataDelay;
  760.                return;
  761.             }
  762.             flvplayback_internal::_autoResizeTimer.reset();
  763.          }
  764.          if(flvplayback_internal::_autoResizeDone)
  765.          {
  766.             setState(flvplayback_internal::_cachedState);
  767.             return;
  768.          }
  769.          oldBounds = new Rectangle(x,y,width,height);
  770.          oldRegistrationBounds = new Rectangle(registrationX,registrationY,registrationWidth,registrationHeight);
  771.          _autoResizeDone = true;
  772.          var _loc2_:Boolean = flvplayback_internal::_readyDispatched;
  773.          _readyDispatched = true;
  774.          _loc3_ = videoWidth;
  775.          _loc4_ = videoHeight;
  776.          _readyDispatched = _loc2_;
  777.          switch(_scaleMode)
  778.          {
  779.             case VideoScaleMode.NO_SCALE:
  780.                super.width = Math.round(_loc3_);
  781.                super.height = Math.round(_loc4_);
  782.                break;
  783.             case VideoScaleMode.EXACT_FIT:
  784.                super.width = registrationWidth;
  785.                super.height = registrationHeight;
  786.                break;
  787.             case VideoScaleMode.MAINTAIN_ASPECT_RATIO:
  788.             default:
  789.                _loc5_ = _loc3_ * _registrationHeight / _loc4_;
  790.                if((_loc6_ = _loc4_ * _registrationWidth / _loc3_) < _registrationHeight)
  791.                {
  792.                   super.width = _registrationWidth;
  793.                   super.height = _loc6_;
  794.                }
  795.                else if(_loc5_ < _registrationWidth)
  796.                {
  797.                   super.width = _loc5_;
  798.                   super.height = _registrationHeight;
  799.                }
  800.                else
  801.                {
  802.                   super.width = _registrationWidth;
  803.                   super.height = _registrationHeight;
  804.                }
  805.          }
  806.          switch(_align)
  807.          {
  808.             case VideoAlign.CENTER:
  809.             case VideoAlign.TOP:
  810.             case VideoAlign.BOTTOM:
  811.             default:
  812.                super.x = Math.round(_registrationX + (_registrationWidth - width) / 2);
  813.                break;
  814.             case VideoAlign.LEFT:
  815.             case VideoAlign.TOP_LEFT:
  816.             case VideoAlign.BOTTOM_LEFT:
  817.                super.x = Math.round(_registrationX);
  818.                break;
  819.             case VideoAlign.RIGHT:
  820.             case VideoAlign.TOP_RIGHT:
  821.             case VideoAlign.BOTTOM_RIGHT:
  822.                super.x = Math.round(_registrationX + (_registrationWidth - width));
  823.          }
  824.          switch(_align)
  825.          {
  826.             case VideoAlign.CENTER:
  827.             case VideoAlign.LEFT:
  828.             case VideoAlign.RIGHT:
  829.             default:
  830.                super.y = Math.round(_registrationY + (_registrationHeight - height) / 2);
  831.                break;
  832.             case VideoAlign.TOP:
  833.             case VideoAlign.TOP_LEFT:
  834.             case VideoAlign.TOP_RIGHT:
  835.                super.y = Math.round(_registrationY);
  836.                break;
  837.             case VideoAlign.BOTTOM:
  838.             case VideoAlign.BOTTOM_LEFT:
  839.             case VideoAlign.BOTTOM_RIGHT:
  840.                super.y = Math.round(_registrationY + (_registrationHeight - height));
  841.          }
  842.          if(flvplayback_internal::_hiddenForResize)
  843.          {
  844.             _hiddenRewindPlayheadTime = playheadTime;
  845.             if(_state == VideoState.LOADING)
  846.             {
  847.                _cachedState = VideoState.PLAYING;
  848.             }
  849.             if(!_ncMgr.isRTMP)
  850.             {
  851.                _pause(true);
  852.                _seek(0);
  853.                flvplayback_internal::_finishAutoResizeTimer.reset();
  854.                flvplayback_internal::_finishAutoResizeTimer.start();
  855.             }
  856.             else if(!_isLive)
  857.             {
  858.                _currentPos = 0;
  859.                _play(0,0);
  860.                setState(VideoState.RESIZING);
  861.             }
  862.             else if(_autoPlay)
  863.             {
  864.                flvplayback_internal::_finishAutoResizeTimer.reset();
  865.                flvplayback_internal::_finishAutoResizeTimer.start();
  866.             }
  867.             else
  868.             {
  869.                finishAutoResize();
  870.             }
  871.          }
  872.          else
  873.          {
  874.             dispatchEvent(new AutoLayoutEvent(AutoLayoutEvent.AUTO_LAYOUT,false,false,flvplayback_internal::oldBounds,flvplayback_internal::oldRegistrationBounds));
  875.          }
  876.       }
  877.       
  878.       public function get totalTime() : Number
  879.       {
  880.          return _streamLength;
  881.       }
  882.       
  883.       public function set volume(param1:Number) : void
  884.       {
  885.          var _loc2_:SoundTransform = soundTransform;
  886.          _loc2_.volume = param1;
  887.          soundTransform = _loc2_;
  888.       }
  889.       
  890.       flvplayback_internal function _play(param1:int = 0, param2:int = -1) : void
  891.       {
  892.          waitingForEnough = false;
  893.          flvplayback_internal::_rtmpDoStopAtEndTimer.reset();
  894.          _startingPlay = true;
  895.          _ns.play(_ncMgr.streamName,!!_isLive ? -1 : param1,param2);
  896.       }
  897.       
  898.       flvplayback_internal function finishAutoResize(param1:TimerEvent = null) : void
  899.       {
  900.          if(stateResponsive)
  901.          {
  902.             return;
  903.          }
  904.          _hiddenForResize = false;
  905.          super.visible = __visible;
  906.          volume = _volume;
  907.          dispatchEvent(new AutoLayoutEvent(AutoLayoutEvent.AUTO_LAYOUT,false,false,flvplayback_internal::oldBounds,flvplayback_internal::oldRegistrationBounds));
  908.          if(_autoPlay)
  909.          {
  910.             if(_ncMgr.isRTMP)
  911.             {
  912.                if(!_isLive)
  913.                {
  914.                   _currentPos = 0;
  915.                   _play(0);
  916.                }
  917.                if(_state == VideoState.RESIZING)
  918.                {
  919.                   setState(VideoState.LOADING);
  920.                   _cachedState = VideoState.PLAYING;
  921.                }
  922.             }
  923.             else
  924.             {
  925.                waitingForEnough = true;
  926.                _cachedState = _state;
  927.                _state = VideoState.PAUSED;
  928.                checkReadyForPlay(bytesLoaded,bytesTotal);
  929.                if(flvplayback_internal::waitingForEnough)
  930.                {
  931.                   _state = flvplayback_internal::_cachedState;
  932.                   setState(VideoState.PAUSED);
  933.                }
  934.                else
  935.                {
  936.                   _cachedState = VideoState.PLAYING;
  937.                }
  938.             }
  939.          }
  940.          else
  941.          {
  942.             setState(VideoState.STOPPED);
  943.          }
  944.       }
  945.       
  946.       public function set soundTransform(param1:SoundTransform) : void
  947.       {
  948.          if(param1 == null)
  949.          {
  950.             return;
  951.          }
  952.          if(flvplayback_internal::_hiddenForResize)
  953.          {
  954.             _volume = param1.volume;
  955.          }
  956.          _soundTransform = new SoundTransform();
  957.          _soundTransform.volume = !!flvplayback_internal::_hiddenForResize ? Number(0) : Number(param1.volume);
  958.          _soundTransform.leftToLeft = param1.leftToLeft;
  959.          _soundTransform.leftToRight = param1.leftToRight;
  960.          _soundTransform.rightToLeft = param1.rightToLeft;
  961.          _soundTransform.rightToRight = param1.rightToRight;
  962.          if(_ns != null)
  963.          {
  964.             _ns.soundTransform = _soundTransform;
  965.          }
  966.       }
  967.       
  968.       flvplayback_internal function onCuePoint(param1:Object) : void
  969.       {
  970.          if(!flvplayback_internal::_hiddenForResize || !isNaN(flvplayback_internal::_hiddenRewindPlayheadTime) && playheadTime < flvplayback_internal::_hiddenRewindPlayheadTime)
  971.          {
  972.             dispatchEvent(new MetadataEvent(MetadataEvent.CUE_POINT,false,false,param1));
  973.          }
  974.       }
  975.       
  976.       flvplayback_internal function httpNetStatus(param1:NetStatusEvent) : void
  977.       {
  978.          switch(param1.info.code)
  979.          {
  980.             case "NetStream.Play.Stop":
  981.                flvplayback_internal::_delayedBufferingTimer.reset();
  982.                if(flvplayback_internal::_invalidSeekTime)
  983.                {
  984.                   _invalidSeekTime = false;
  985.                   _invalidSeekRecovery = true;
  986.                   setState(flvplayback_internal::_cachedState);
  987.                   seek(playheadTime);
  988.                }
  989.                else
  990.                {
  991.                   switch(_state)
  992.                   {
  993.                      case VideoState.SEEKING:
  994.                         httpDoSeek(null);
  995.                      case VideoState.PLAYING:
  996.                      case VideoState.BUFFERING:
  997.                         httpDoStopAtEnd();
  998.                   }
  999.                }
  1000.                break;
  1001.             case "NetStream.Seek.InvalidTime":
  1002.                if(flvplayback_internal::_invalidSeekRecovery)
  1003.                {
  1004.                   _invalidSeekTime = false;
  1005.                   _invalidSeekRecovery = false;
  1006.                   setState(flvplayback_internal::_cachedState);
  1007.                   seek(0);
  1008.                }
  1009.                else
  1010.                {
  1011.                   _invalidSeekTime = true;
  1012.                   _httpDoSeekCount = 0;
  1013.                   flvplayback_internal::_httpDoSeekTimer.start();
  1014.                }
  1015.                break;
  1016.             case "NetStream.Buffer.Empty":
  1017.                _bufferState = flvplayback_internal::BUFFER_EMPTY;
  1018.                if(_state == VideoState.PLAYING)
  1019.                {
  1020.                   flvplayback_internal::_delayedBufferingTimer.reset();
  1021.                   flvplayback_internal::_delayedBufferingTimer.start();
  1022.                }
  1023.                break;
  1024.             case "NetStream.Buffer.Full":
  1025.             case "NetStream.Buffer.Flush":
  1026.                flvplayback_internal::_delayedBufferingTimer.reset();
  1027.                _bufferState = flvplayback_internal::BUFFER_FULL;
  1028.                if(!flvplayback_internal::_hiddenForResize)
  1029.                {
  1030.                   if(_state == VideoState.LOADING && flvplayback_internal::_cachedState == VideoState.PLAYING || _state == VideoState.BUFFERING)
  1031.                   {
  1032.                      setState(VideoState.PLAYING);
  1033.                   }
  1034.                   else if(flvplayback_internal::_cachedState == VideoState.BUFFERING)
  1035.                   {
  1036.                      _cachedState = VideoState.PLAYING;
  1037.                   }
  1038.                }
  1039.                break;
  1040.             case "NetStream.Seek.Notify":
  1041.                _invalidSeekRecovery = false;
  1042.                switch(_state)
  1043.                {
  1044.                   case VideoState.SEEKING:
  1045.                   case VideoState.REWINDING:
  1046.                      _httpDoSeekCount = 0;
  1047.                      flvplayback_internal::_httpDoSeekTimer.start();
  1048.                }
  1049.                break;
  1050.             case "NetStream.Play.StreamNotFound":
  1051.             case "NetStream.Play.FileStructureInvalid":
  1052.             case "NetStream.Play.NoSupportedTrackFound":
  1053.                setState(VideoState.CONNECTION_ERROR);
  1054.          }
  1055.       }
  1056.       
  1057.       flvplayback_internal function httpDoSeek(param1:TimerEvent) : void
  1058.       {
  1059.          var _loc2_:Boolean = _state == VideoState.REWINDING || _state == VideoState.SEEKING;
  1060.          if(_loc2_ && flvplayback_internal::_httpDoSeekCount < flvplayback_internal::httpDoSeekMaxCount && (flvplayback_internal::_cachedPlayheadTime == playheadTime || flvplayback_internal::_invalidSeekTime))
  1061.          {
  1062.             ++_httpDoSeekCount;
  1063.             return;
  1064.          }
  1065.          _httpDoSeekCount = 0;
  1066.          flvplayback_internal::_httpDoSeekTimer.reset();
  1067.          if(!_loc2_)
  1068.          {
  1069.             return;
  1070.          }
  1071.          setStateFromCachedState(false);
  1072.          if(flvplayback_internal::_invalidSeekTime)
  1073.          {
  1074.             _invalidSeekTime = false;
  1075.             _invalidSeekRecovery = true;
  1076.             seek(playheadTime);
  1077.          }
  1078.          else
  1079.          {
  1080.             doUpdateTime();
  1081.             _lastSeekTime = playheadTime;
  1082.             execQueuedCmds();
  1083.          }
  1084.       }
  1085.       
  1086.       override public function set height(param1:Number) : void
  1087.       {
  1088.          super.height = _registrationHeight = param1;
  1089.          switch(_scaleMode)
  1090.          {
  1091.             case VideoScaleMode.MAINTAIN_ASPECT_RATIO:
  1092.             case VideoScaleMode.NO_SCALE:
  1093.                startAutoResize();
  1094.                break;
  1095.             default:
  1096.                super.height = param1;
  1097.          }
  1098.       }
  1099.       
  1100.       public function get bytesLoaded() : uint
  1101.       {
  1102.          if(_ns == null || _ncMgr.isRTMP)
  1103.          {
  1104.             return uint.MIN_VALUE;
  1105.          }
  1106.          return _ns.bytesLoaded;
  1107.       }
  1108.       
  1109.       public function set bufferTime(param1:Number) : void
  1110.       {
  1111.          _bufferTime = param1;
  1112.          if(_ns != null)
  1113.          {
  1114.             _ns.bufferTime = _bufferTime;
  1115.          }
  1116.       }
  1117.       
  1118.       public function get netConnection() : NetConnection
  1119.       {
  1120.          if(_ncMgr != null)
  1121.          {
  1122.             return _ncMgr.netConnection;
  1123.          }
  1124.          return null;
  1125.       }
  1126.       
  1127.       flvplayback_internal function onMetaData(param1:Object) : void
  1128.       {
  1129.          if(_metadata != null)
  1130.          {
  1131.             return;
  1132.          }
  1133.          _metadata = param1;
  1134.          if(isNaN(_streamLength))
  1135.          {
  1136.             _streamLength = param1.duration;
  1137.          }
  1138.          if(flvplayback_internal::_resizeImmediatelyOnMetadata && _ns.client.ready)
  1139.          {
  1140.             _resizeImmediatelyOnMetadata = false;
  1141.             flvplayback_internal::_autoResizeTimer.reset();
  1142.             _autoResizeDone = false;
  1143.             doAutoResize();
  1144.          }
  1145.          dispatchEvent(new MetadataEvent(MetadataEvent.METADATA_RECEIVED,false,false,param1));
  1146.       }
  1147.       
  1148.       flvplayback_internal function queueCmd(param1:Number, param2:String = null, param3:Boolean = false, param4:Number = NaN) : void
  1149.       {
  1150.          flvplayback_internal::_cmdQueue.push(new QueuedCommand(param1,param2,param3,param4));
  1151.       }
  1152.       
  1153.       public function seek(param1:Number) : void
  1154.       {
  1155.          if(flvplayback_internal::_invalidSeekTime)
  1156.          {
  1157.             return;
  1158.          }
  1159.          if(isNaN(param1) || param1 < 0)
  1160.          {
  1161.             throw new VideoError(VideoError.INVALID_SEEK);
  1162.          }
  1163.          if(!isXnOK())
  1164.          {
  1165.             if(_state == VideoState.CONNECTION_ERROR || _ncMgr == null || _ncMgr.netConnection == null)
  1166.             {
  1167.                throw new VideoError(VideoError.NO_CONNECTION);
  1168.             }
  1169.             flushQueuedCmds();
  1170.             queueCmd(QueuedCommand.SEEK,null,false,param1);
  1171.             setState(VideoState.LOADING);
  1172.             _cachedState = VideoState.LOADING;
  1173.             _ncMgr.reconnect();
  1174.             return;
  1175.          }
  1176.          if(_state == VideoState.EXEC_QUEUED_CMD)
  1177.          {
  1178.             _state = flvplayback_internal::_cachedState;
  1179.          }
  1180.          else
  1181.          {
  1182.             if(!stateResponsive)
  1183.             {
  1184.                queueCmd(QueuedCommand.SEEK,null,false,param1);
  1185.                return;
  1186.             }
  1187.             execQueuedCmds();
  1188.          }
  1189.          if(_ns == null)
  1190.          {
  1191.             _createStream();
  1192.          }
  1193.          if(flvplayback_internal::_atEnd && param1 < playheadTime)
  1194.          {
  1195.             _atEnd = false;
  1196.          }
  1197.          switch(_state)
  1198.          {
  1199.             case VideoState.PLAYING:
  1200.                _state = VideoState.BUFFERING;
  1201.             case VideoState.BUFFERING:
  1202.             case VideoState.PAUSED:
  1203.                _seek(param1);
  1204.                setState(VideoState.SEEKING);
  1205.                break;
  1206.             case VideoState.STOPPED:
  1207.                if(_ncMgr.isRTMP)
  1208.                {
  1209.                   _play(0);
  1210.                   _pause(true);
  1211.                }
  1212.                _seek(param1);
  1213.                _state = VideoState.PAUSED;
  1214.                setState(VideoState.SEEKING);
  1215.          }
  1216.       }
  1217.       
  1218.       public function set registrationHeight(param1:Number) : void
  1219.       {
  1220.          height = param1;
  1221.       }
  1222.       
  1223.       override public function get visible() : Boolean
  1224.       {
  1225.          if(!flvplayback_internal::_hiddenForResize)
  1226.          {
  1227.             __visible = super.visible;
  1228.          }
  1229.          return __visible;
  1230.       }
  1231.       
  1232.       public function get registrationWidth() : Number
  1233.       {
  1234.          return _registrationWidth;
  1235.       }
  1236.       
  1237.       public function get state() : String
  1238.       {
  1239.          return _state;
  1240.       }
  1241.       
  1242.       public function set autoRewind(param1:Boolean) : void
  1243.       {
  1244.          _autoRewind = param1;
  1245.       }
  1246.       
  1247.       override public function set scaleX(param1:Number) : void
  1248.       {
  1249.          super.scaleX = param1;
  1250.          _registrationWidth = width;
  1251.          switch(_scaleMode)
  1252.          {
  1253.             case VideoScaleMode.MAINTAIN_ASPECT_RATIO:
  1254.             case VideoScaleMode.NO_SCALE:
  1255.                startAutoResize();
  1256.          }
  1257.       }
  1258.       
  1259.       override public function set scaleY(param1:Number) : void
  1260.       {
  1261.          super.scaleY = param1;
  1262.          _registrationHeight = height;
  1263.          switch(_scaleMode)
  1264.          {
  1265.             case VideoScaleMode.MAINTAIN_ASPECT_RATIO:
  1266.             case VideoScaleMode.NO_SCALE:
  1267.                startAutoResize();
  1268.          }
  1269.       }
  1270.       
  1271.       flvplayback_internal function flushQueuedCmds() : void
  1272.       {
  1273.          while(flvplayback_internal::_cmdQueue.length > 0)
  1274.          {
  1275.             flvplayback_internal::_cmdQueue.pop();
  1276.          }
  1277.       }
  1278.       
  1279.       public function get registrationX() : Number
  1280.       {
  1281.          return _registrationX;
  1282.       }
  1283.       
  1284.       flvplayback_internal function _setUpStream() : void
  1285.       {
  1286.          if(!isNaN(_ncMgr.streamLength) && _ncMgr.streamLength >= 0)
  1287.          {
  1288.             _streamLength = _ncMgr.streamLength;
  1289.          }
  1290.          _videoWidth = _ncMgr.streamWidth >= 0 ? int(_ncMgr.streamWidth) : -1;
  1291.          _videoHeight = _ncMgr.streamHeight >= 0 ? int(_ncMgr.streamHeight) : -1;
  1292.          _resizeImmediatelyOnMetadata = _videoWidth >= 0 && _videoHeight >= 0 || _scaleMode == VideoScaleMode.EXACT_FIT;
  1293.          if(!flvplayback_internal::_hiddenForResize)
  1294.          {
  1295.             __visible = super.visible;
  1296.             super.visible = false;
  1297.             _volume = volume;
  1298.             volume = 0;
  1299.             _hiddenForResize = true;
  1300.          }
  1301.          _hiddenForResizeMetadataDelay = 0;
  1302.          _play(0);
  1303.          if(flvplayback_internal::_currentPos > 0)
  1304.          {
  1305.             _seek(flvplayback_internal::_currentPos);
  1306.             _currentPos = 0;
  1307.          }
  1308.          flvplayback_internal::_autoResizeTimer.reset();
  1309.          flvplayback_internal::_autoResizeTimer.start();
  1310.       }
  1311.       
  1312.       public function get registrationY() : Number
  1313.       {
  1314.          return _registrationY;
  1315.       }
  1316.       
  1317.       flvplayback_internal function httpDoStopAtEnd() : void
  1318.       {
  1319.          if(flvplayback_internal::_atEndCheckPlayhead == playheadTime && flvplayback_internal::_atEndCheckPlayhead != flvplayback_internal::_lastUpdateTime && playheadTime != 0)
  1320.          {
  1321.             _atEnd = false;
  1322.             _seek(0);
  1323.             return;
  1324.          }
  1325.          _atEndCheckPlayhead = NaN;
  1326.          _atEnd = true;
  1327.          if(isNaN(_streamLength))
  1328.          {
  1329.             _streamLength = _ns.time;
  1330.          }
  1331.          _pause(true);
  1332.          setState(VideoState.STOPPED);
  1333.          if(_state != VideoState.STOPPED)
  1334.          {
  1335.             return;
  1336.          }
  1337.          doUpdateTime();
  1338.          if(_state != VideoState.STOPPED)
  1339.          {
  1340.             return;
  1341.          }
  1342.          dispatchEvent(new VideoEvent(VideoEvent.COMPLETE,false,false,_state,playheadTime));
  1343.          if(_state != VideoState.STOPPED)
  1344.          {
  1345.             return;
  1346.          }
  1347.          if(_autoRewind)
  1348.          {
  1349.             _atEnd = false;
  1350.             _pause(true);
  1351.             _seek(0);
  1352.             setState(VideoState.REWINDING);
  1353.          }
  1354.       }
  1355.       
  1356.       public function ncConnected() : void
  1357.       {
  1358.          if(_ncMgr == null || _ncMgr.netConnection == null)
  1359.          {
  1360.             setState(VideoState.CONNECTION_ERROR);
  1361.          }
  1362.          else if(_ns == null)
  1363.          {
  1364.             _createStream();
  1365.             _setUpStream();
  1366.          }
  1367.       }
  1368.       
  1369.       override public function set visible(param1:Boolean) : void
  1370.       {
  1371.          __visible = param1;
  1372.          if(!flvplayback_internal::_hiddenForResize)
  1373.          {
  1374.             super.visible = __visible;
  1375.          }
  1376.       }
  1377.       
  1378.       public function get idleTimeout() : Number
  1379.       {
  1380.          return flvplayback_internal::_idleTimeoutTimer.delay;
  1381.       }
  1382.       
  1383.       public function get playheadUpdateInterval() : Number
  1384.       {
  1385.          return flvplayback_internal::_updateTimeTimer.delay;
  1386.       }
  1387.       
  1388.       override public function set y(param1:Number) : void
  1389.       {
  1390.          var _loc2_:Number = NaN;
  1391.          if(this.y != param1)
  1392.          {
  1393.             _loc2_ = param1 - this.y;
  1394.             super.y = param1;
  1395.             _registrationY += _loc2_;
  1396.          }
  1397.       }
  1398.       
  1399.       public function load(param1:String, param2:Number = NaN, param3:Boolean = false) : void
  1400.       {
  1401.          if(param1 == null)
  1402.          {
  1403.             throw new VideoError(VideoError.NULL_URL_LOAD);
  1404.          }
  1405.          if(_state == VideoState.EXEC_QUEUED_CMD)
  1406.          {
  1407.             _state = flvplayback_internal::_cachedState;
  1408.          }
  1409.          else
  1410.          {
  1411.             if(!stateResponsive && _state != VideoState.DISCONNECTED && _state != VideoState.CONNECTION_ERROR)
  1412.             {
  1413.                queueCmd(QueuedCommand.LOAD,param1,param3,param2);
  1414.                return;
  1415.             }
  1416.             execQueuedCmds();
  1417.          }
  1418.          _autoPlay = false;
  1419.          _load(param1,param2,param3);
  1420.       }
  1421.       
  1422.       override public function set x(param1:Number) : void
  1423.       {
  1424.          var _loc2_:Number = NaN;
  1425.          if(this.x != param1)
  1426.          {
  1427.             _loc2_ = param1 - this.x;
  1428.             super.x = param1;
  1429.             _registrationX += _loc2_;
  1430.          }
  1431.       }
  1432.       
  1433.       flvplayback_internal function doDelayedBuffering(param1:TimerEvent) : void
  1434.       {
  1435.          switch(_state)
  1436.          {
  1437.             case VideoState.LOADING:
  1438.             case VideoState.RESIZING:
  1439.                break;
  1440.             case VideoState.PLAYING:
  1441.                flvplayback_internal::_delayedBufferingTimer.reset();
  1442.                if(!isNaN(totalTime) && totalTime > 0 && bytesLoaded > 0 && bytesLoaded < uint.MAX_VALUE && bytesLoaded < bytesTotal)
  1443.                {
  1444.                   pause();
  1445.                   if(_state == VideoState.PAUSED)
  1446.                   {
  1447.                      waitingForEnough = true;
  1448.                      playWhenEnoughDownloaded();
  1449.                   }
  1450.                }
  1451.                else
  1452.                {
  1453.                   setState(VideoState.BUFFERING);
  1454.                }
  1455.                break;
  1456.             default:
  1457.                flvplayback_internal::_delayedBufferingTimer.reset();
  1458.          }
  1459.       }
  1460.       
  1461.       flvplayback_internal function _pause(param1:Boolean) : void
  1462.       {
  1463.          _atEndCheckPlayhead = playheadTime;
  1464.          flvplayback_internal::_rtmpDoStopAtEndTimer.reset();
  1465.          if(param1)
  1466.          {
  1467.             _ns.pause();
  1468.          }
  1469.          else
  1470.          {
  1471.             _ns.resume();
  1472.          }
  1473.       }
  1474.       
  1475.       flvplayback_internal function createNetStreamClient() : Object
  1476.       {
  1477.          var theClass:Class = null;
  1478.          var theInst:Object = null;
  1479.          try
  1480.          {
  1481.             if(netStreamClientClass is String)
  1482.             {
  1483.                theClass = Class(getDefinitionByName(String(netStreamClientClass)));
  1484.             }
  1485.             else if(netStreamClientClass is Class)
  1486.             {
  1487.                theClass = Class(netStreamClientClass);
  1488.             }
  1489.             if(theClass != null)
  1490.             {
  1491.                theInst = new theClass(this);
  1492.             }
  1493.          }
  1494.          catch(e:Error)
  1495.          {
  1496.             theClass = null;
  1497.             theInst = null;
  1498.          }
  1499.          if(theInst == null)
  1500.          {
  1501.             throw new VideoError(VideoError.NETSTREAM_CLIENT_CLASS_UNSET,netStreamClientClass == null ? "null" : netStreamClientClass.toString());
  1502.          }
  1503.          return theInst;
  1504.       }
  1505.       
  1506.       public function get align() : String
  1507.       {
  1508.          return _align;
  1509.       }
  1510.       
  1511.       public function set registrationWidth(param1:Number) : void
  1512.       {
  1513.          width = param1;
  1514.       }
  1515.       
  1516.       public function get soundTransform() : SoundTransform
  1517.       {
  1518.          if(_ns != null)
  1519.          {
  1520.             _soundTransform = _ns.soundTransform;
  1521.          }
  1522.          var _loc1_:SoundTransform = new SoundTransform();
  1523.          _loc1_.volume = !!flvplayback_internal::_hiddenForResize ? Number(_volume) : Number(_soundTransform.volume);
  1524.          _loc1_.leftToLeft = _soundTransform.leftToLeft;
  1525.          _loc1_.leftToRight = _soundTransform.leftToRight;
  1526.          _loc1_.rightToLeft = _soundTransform.rightToLeft;
  1527.          _loc1_.rightToRight = _soundTransform.rightToRight;
  1528.          return _loc1_;
  1529.       }
  1530.       
  1531.       public function get volume() : Number
  1532.       {
  1533.          return soundTransform.volume;
  1534.       }
  1535.       
  1536.       public function get stateResponsive() : Boolean
  1537.       {
  1538.          switch(_state)
  1539.          {
  1540.             case VideoState.STOPPED:
  1541.             case VideoState.PLAYING:
  1542.             case VideoState.PAUSED:
  1543.             case VideoState.BUFFERING:
  1544.                return true;
  1545.             default:
  1546.                return false;
  1547.          }
  1548.       }
  1549.       
  1550.       public function get bufferTime() : Number
  1551.       {
  1552.          if(_ns != null)
  1553.          {
  1554.             _bufferTime = _ns.bufferTime;
  1555.          }
  1556.          return _bufferTime;
  1557.       }
  1558.       
  1559.       public function get metadata() : Object
  1560.       {
  1561.          return _metadata;
  1562.       }
  1563.       
  1564.       public function play(param1:String = null, param2:Number = NaN, param3:Boolean = false) : void
  1565.       {
  1566.          if(param1 != null)
  1567.          {
  1568.             if(_state == VideoState.EXEC_QUEUED_CMD)
  1569.             {
  1570.                _state = flvplayback_internal::_cachedState;
  1571.             }
  1572.             else
  1573.             {
  1574.                if(!stateResponsive && _state != VideoState.DISCONNECTED && _state != VideoState.CONNECTION_ERROR)
  1575.                {
  1576.                   queueCmd(QueuedCommand.PLAY,param1,param3,param2);
  1577.                   return;
  1578.                }
  1579.                execQueuedCmds();
  1580.             }
  1581.             _autoPlay = true;
  1582.             _load(param1,param2,param3);
  1583.             return;
  1584.          }
  1585.          if(!isXnOK())
  1586.          {
  1587.             if(_state == VideoState.CONNECTION_ERROR || _ncMgr == null || _ncMgr.netConnection == null)
  1588.             {
  1589.                throw new VideoError(VideoError.NO_CONNECTION);
  1590.             }
  1591.             flushQueuedCmds();
  1592.             queueCmd(QueuedCommand.PLAY);
  1593.             setState(VideoState.LOADING);
  1594.             _cachedState = VideoState.LOADING;
  1595.             _ncMgr.reconnect();
  1596.             return;
  1597.          }
  1598.          if(_state == VideoState.EXEC_QUEUED_CMD)
  1599.          {
  1600.             _state = flvplayback_internal::_cachedState;
  1601.          }
  1602.          else
  1603.          {
  1604.             if(!stateResponsive)
  1605.             {
  1606.                queueCmd(QueuedCommand.PLAY);
  1607.                return;
  1608.             }
  1609.             execQueuedCmds();
  1610.          }
  1611.          if(_ns == null)
  1612.          {
  1613.             _createStream();
  1614.          }
  1615.          switch(_state)
  1616.          {
  1617.             case VideoState.BUFFERING:
  1618.                if(_ncMgr.isRTMP)
  1619.                {
  1620.                   _play(0);
  1621.                   if(flvplayback_internal::_atEnd)
  1622.                   {
  1623.                      _atEnd = false;
  1624.                      _currentPos = 0;
  1625.                      setState(VideoState.REWINDING);
  1626.                   }
  1627.                   else if(flvplayback_internal::_currentPos > 0)
  1628.                   {
  1629.                      _seek(flvplayback_internal::_currentPos);
  1630.                      _currentPos = 0;
  1631.                   }
  1632.                }
  1633.             case VideoState.PLAYING:
  1634.                return;
  1635.             case VideoState.STOPPED:
  1636.                if(_ncMgr.isRTMP)
  1637.                {
  1638.                   if(_isLive)
  1639.                   {
  1640.                      _play(-1);
  1641.                      setState(VideoState.BUFFERING);
  1642.                   }
  1643.                   else
  1644.                   {
  1645.                      _play(0);
  1646.                      if(flvplayback_internal::_atEnd)
  1647.                      {
  1648.                         _atEnd = false;
  1649.                         _currentPos = 0;
  1650.                         _state = VideoState.BUFFERING;
  1651.                         setState(VideoState.REWINDING);
  1652.                      }
  1653.                      else if(flvplayback_internal::_currentPos > 0)
  1654.                      {
  1655.                         _seek(flvplayback_internal::_currentPos);
  1656.                         _currentPos = 0;
  1657.                         setState(VideoState.BUFFERING);
  1658.                      }
  1659.                      else
  1660.                      {
  1661.                         setState(VideoState.BUFFERING);
  1662.                      }
  1663.                   }
  1664.                }
  1665.                else
  1666.                {
  1667.                   _pause(false);
  1668.                   if(flvplayback_internal::_atEnd)
  1669.                   {
  1670.                      _atEnd = false;
  1671.                      _seek(0);
  1672.                      _state = VideoState.BUFFERING;
  1673.                      setState(VideoState.REWINDING);
  1674.                   }
  1675.                   else if(flvplayback_internal::_bufferState == flvplayback_internal::BUFFER_EMPTY)
  1676.                   {
  1677.                      setState(VideoState.BUFFERING);
  1678.                   }
  1679.                   else
  1680.                   {
  1681.                      setState(VideoState.PLAYING);
  1682.                   }
  1683.                }
  1684.                break;
  1685.             case VideoState.PAUSED:
  1686.                _pause(false);
  1687.                if(!_ncMgr.isRTMP)
  1688.                {
  1689.                   if(flvplayback_internal::_bufferState == flvplayback_internal::BUFFER_EMPTY)
  1690.                   {
  1691.                      setState(VideoState.BUFFERING);
  1692.                   }
  1693.                   else
  1694.                   {
  1695.                      setState(VideoState.PLAYING);
  1696.                   }
  1697.                }
  1698.                else
  1699.                {
  1700.                   setState(VideoState.BUFFERING);
  1701.                }
  1702.          }
  1703.       }
  1704.       
  1705.       public function get isLive() : Boolean
  1706.       {
  1707.          return _isLive;
  1708.       }
  1709.       
  1710.       flvplayback_internal function setStateFromCachedState(param1:Boolean = true) : void
  1711.       {
  1712.          switch(flvplayback_internal::_cachedState)
  1713.          {
  1714.             case VideoState.PLAYING:
  1715.             case VideoState.PAUSED:
  1716.             case VideoState.BUFFERING:
  1717.                setState(flvplayback_internal::_cachedState,param1);
  1718.                break;
  1719.             default:
  1720.                setState(VideoState.STOPPED,param1);
  1721.          }
  1722.       }
  1723.       
  1724.       public function ncReconnected() : void
  1725.       {
  1726.          if(_ncMgr == null || _ncMgr.netConnection == null)
  1727.          {
  1728.             setState(VideoState.CONNECTION_ERROR);
  1729.          }
  1730.          else
  1731.          {
  1732.             _ns = null;
  1733.             _state = VideoState.STOPPED;
  1734.             execQueuedCmds();
  1735.          }
  1736.       }
  1737.       
  1738.       public function get registrationHeight() : Number
  1739.       {
  1740.          return _registrationHeight;
  1741.       }
  1742.       
  1743.       public function get autoRewind() : Boolean
  1744.       {
  1745.          return _autoRewind;
  1746.       }
  1747.       
  1748.       flvplayback_internal function startAutoResize() : void
  1749.       {
  1750.          switch(_state)
  1751.          {
  1752.             case VideoState.DISCONNECTED:
  1753.             case VideoState.CONNECTION_ERROR:
  1754.                return;
  1755.             default:
  1756.                if(_ns == null)
  1757.                {
  1758.                   return;
  1759.                }
  1760.                _autoResizeDone = false;
  1761.                if(stateResponsive && (super.videoWidth != 0 || super.videoHeight != 0 || flvplayback_internal::_bufferState == flvplayback_internal::BUFFER_FULL || flvplayback_internal::_bufferState == flvplayback_internal::BUFFER_FLUSH || _ns.time > flvplayback_internal::autoResizePlayheadTimeout))
  1762.                {
  1763.                   doAutoResize();
  1764.                }
  1765.                else
  1766.                {
  1767.                   flvplayback_internal::_autoResizeTimer.reset();
  1768.                   flvplayback_internal::_autoResizeTimer.start();
  1769.                }
  1770.                return;
  1771.          }
  1772.       }
  1773.       
  1774.       flvplayback_internal function setState(param1:String, param2:Boolean = true) : void
  1775.       {
  1776.          if(param1 == _state)
  1777.          {
  1778.             return;
  1779.          }
  1780.          _hiddenRewindPlayheadTime = NaN;
  1781.          _cachedState = _state;
  1782.          _cachedPlayheadTime = playheadTime;
  1783.          _state = param1;
  1784.          var _loc3_:String = _state;
  1785.          dispatchEvent(new VideoEvent(VideoEvent.STATE_CHANGE,false,false,_loc3_,playheadTime));
  1786.          if(!flvplayback_internal::_readyDispatched)
  1787.          {
  1788.             switch(_loc3_)
  1789.             {
  1790.                case VideoState.STOPPED:
  1791.                case VideoState.PLAYING:
  1792.                case VideoState.PAUSED:
  1793.                case VideoState.BUFFERING:
  1794.                   _readyDispatched = true;
  1795.                   dispatchEvent(new VideoEvent(VideoEvent.READY,false,false,_loc3_,playheadTime));
  1796.             }
  1797.          }
  1798.          switch(flvplayback_internal::_cachedState)
  1799.          {
  1800.             case VideoState.REWINDING:
  1801.                dispatchEvent(new VideoEvent(VideoEvent.AUTO_REWOUND,false,false,_loc3_,playheadTime));
  1802.                if(_ncMgr.isRTMP && _loc3_ == VideoState.STOPPED)
  1803.                {
  1804.                   closeNS();
  1805.                }
  1806.          }
  1807.          switch(_loc3_)
  1808.          {
  1809.             case VideoState.STOPPED:
  1810.             case VideoState.PAUSED:
  1811.                if(_ncMgr.isRTMP)
  1812.                {
  1813.                   flvplayback_internal::_idleTimeoutTimer.reset();
  1814.                   flvplayback_internal::_idleTimeoutTimer.start();
  1815.                }
  1816.                break;
  1817.             case VideoState.SEEKING:
  1818.             case VideoState.REWINDING:
  1819.                _bufferState = flvplayback_internal::BUFFER_EMPTY;
  1820.                _sawPlayStop = false;
  1821.                flvplayback_internal::_idleTimeoutTimer.reset();
  1822.                break;
  1823.             case VideoState.PLAYING:
  1824.             case VideoState.BUFFERING:
  1825.                flvplayback_internal::_updateTimeTimer.start();
  1826.                flvplayback_internal::_idleTimeoutTimer.reset();
  1827.                break;
  1828.             case VideoState.LOADING:
  1829.             case VideoState.RESIZING:
  1830.                flvplayback_internal::_idleTimeoutTimer.reset();
  1831.          }
  1832.          if(param2)
  1833.          {
  1834.             execQueuedCmds();
  1835.          }
  1836.       }
  1837.       
  1838.       flvplayback_internal function _seek(param1:Number) : void
  1839.       {
  1840.          flvplayback_internal::_rtmpDoStopAtEndTimer.reset();
  1841.          if(_metadata != null && _metadata.audiodelay != undefined && (isNaN(_streamLength) || param1 + _metadata.audiodelay < _streamLength))
  1842.          {
  1843.             param1 += _metadata.audiodelay;
  1844.          }
  1845.          _ns.seek(param1);
  1846.          _lastSeekTime = param1;
  1847.          _invalidSeekTime = false;
  1848.          _bufferState = flvplayback_internal::BUFFER_EMPTY;
  1849.          _sawPlayStop = false;
  1850.          _sawSeekNotify = false;
  1851.       }
  1852.       
  1853.       flvplayback_internal function doIdleTimeout(param1:TimerEvent) : void
  1854.       {
  1855.          close();
  1856.       }
  1857.       
  1858.       public function playWhenEnoughDownloaded() : void
  1859.       {
  1860.          if(_ncMgr != null && _ncMgr.isRTMP)
  1861.          {
  1862.             play();
  1863.             return;
  1864.          }
  1865.          if(!isXnOK())
  1866.          {
  1867.             throw new VideoError(VideoError.NO_CONNECTION);
  1868.          }
  1869.          if(_state == VideoState.EXEC_QUEUED_CMD)
  1870.          {
  1871.             _state = flvplayback_internal::_cachedState;
  1872.          }
  1873.          else
  1874.          {
  1875.             if(!stateResponsive)
  1876.             {
  1877.                queueCmd(QueuedCommand.PLAY_WHEN_ENOUGH);
  1878.                return;
  1879.             }
  1880.             execQueuedCmds();
  1881.          }
  1882.          waitingForEnough = true;
  1883.          checkReadyForPlay(bytesLoaded,bytesTotal);
  1884.       }
  1885.       
  1886.       flvplayback_internal function rtmpDoSeek(param1:TimerEvent) : void
  1887.       {
  1888.          if(_state != VideoState.REWINDING && _state != VideoState.SEEKING)
  1889.          {
  1890.             flvplayback_internal::_rtmpDoSeekTimer.reset();
  1891.             _sawSeekNotify = false;
  1892.          }
  1893.          else if(playheadTime != flvplayback_internal::_cachedPlayheadTime)
  1894.          {
  1895.             flvplayback_internal::_rtmpDoSeekTimer.reset();
  1896.             _sawSeekNotify = false;
  1897.             setStateFromCachedState(false);
  1898.             doUpdateTime();
  1899.             _lastSeekTime = playheadTime;
  1900.             execQueuedCmds();
  1901.          }
  1902.       }
  1903.       
  1904.       public function get netStream() : NetStream
  1905.       {
  1906.          return _ns;
  1907.       }
  1908.       
  1909.       public function set registrationX(param1:Number) : void
  1910.       {
  1911.          var _loc2_:Number = NaN;
  1912.          if(_registrationX != param1)
  1913.          {
  1914.             _loc2_ = param1 - _registrationX;
  1915.             _registrationX = param1;
  1916.             this.x += _loc2_;
  1917.          }
  1918.       }
  1919.       
  1920.       flvplayback_internal function doUpdateProgress(param1:TimerEvent) : void
  1921.       {
  1922.          if(_ns == null)
  1923.          {
  1924.             return;
  1925.          }
  1926.          var _loc2_:uint = _ns.bytesLoaded;
  1927.          var _loc3_:uint = _ns.bytesTotal;
  1928.          if(_loc3_ < uint.MAX_VALUE)
  1929.          {
  1930.             dispatchEvent(new VideoProgressEvent(VideoProgressEvent.PROGRESS,false,false,_loc2_,_loc3_));
  1931.          }
  1932.          if(_state == VideoState.DISCONNECTED || _state == VideoState.CONNECTION_ERROR || _loc2_ >= _loc3_)
  1933.          {
  1934.             flvplayback_internal::_updateProgressTimer.stop();
  1935.          }
  1936.          checkEnoughDownloaded(_loc2_,_loc3_);
  1937.       }
  1938.       
  1939.       public function set registrationY(param1:Number) : void
  1940.       {
  1941.          var _loc2_:Number = NaN;
  1942.          if(_registrationY != param1)
  1943.          {
  1944.             _loc2_ = param1 - _registrationY;
  1945.             _registrationY = param1;
  1946.             this.y += _loc2_;
  1947.          }
  1948.       }
  1949.       
  1950.       override public function get videoHeight() : int
  1951.       {
  1952.          if(_videoHeight > 0)
  1953.          {
  1954.             return _videoHeight;
  1955.          }
  1956.          if(_metadata != null && !isNaN(_metadata.width) && !isNaN(_metadata.height))
  1957.          {
  1958.             if(_metadata.width == _metadata.height && flvplayback_internal::_readyDispatched)
  1959.             {
  1960.                return super.videoHeight;
  1961.             }
  1962.             return int(_metadata.height);
  1963.          }
  1964.          if(flvplayback_internal::_readyDispatched)
  1965.          {
  1966.             return super.videoHeight;
  1967.          }
  1968.          return -1;
  1969.       }
  1970.       
  1971.       public function setSize(param1:Number, param2:Number) : void
  1972.       {
  1973.          super.width = _registrationWidth = param1;
  1974.          super.height = _registrationHeight = param2;
  1975.          switch(_scaleMode)
  1976.          {
  1977.             case VideoScaleMode.MAINTAIN_ASPECT_RATIO:
  1978.             case VideoScaleMode.NO_SCALE:
  1979.                startAutoResize();
  1980.                break;
  1981.             default:
  1982.                super.x = _registrationX;
  1983.                super.y = _registrationY;
  1984.          }
  1985.       }
  1986.       
  1987.       public function get isRTMP() : Boolean
  1988.       {
  1989.          if(_ncMgr == null)
  1990.          {
  1991.             return false;
  1992.          }
  1993.          return _ncMgr.isRTMP;
  1994.       }
  1995.       
  1996.       override public function set width(param1:Number) : void
  1997.       {
  1998.          super.width = _registrationWidth = param1;
  1999.          switch(_scaleMode)
  2000.          {
  2001.             case VideoScaleMode.MAINTAIN_ASPECT_RATIO:
  2002.             case VideoScaleMode.NO_SCALE:
  2003.                startAutoResize();
  2004.                break;
  2005.             default:
  2006.                super.width = param1;
  2007.          }
  2008.       }
  2009.       
  2010.       public function get bytesTotal() : uint
  2011.       {
  2012.          if(_ns == null || _ncMgr.isRTMP)
  2013.          {
  2014.             return uint.MAX_VALUE;
  2015.          }
  2016.          return _ns.bytesTotal;
  2017.       }
  2018.       
  2019.       flvplayback_internal function isXnOK() : Boolean
  2020.       {
  2021.          if(_state == VideoState.LOADING)
  2022.          {
  2023.             return true;
  2024.          }
  2025.          if(_state == VideoState.CONNECTION_ERROR)
  2026.          {
  2027.             return false;
  2028.          }
  2029.          if(_state != VideoState.DISCONNECTED)
  2030.          {
  2031.             if(_ncMgr == null || _ncMgr.netConnection == null || _ncMgr.isRTMP && !_ncMgr.netConnection.connected)
  2032.             {
  2033.                setState(VideoState.DISCONNECTED);
  2034.                return false;
  2035.             }
  2036.             return true;
  2037.          }
  2038.          return false;
  2039.       }
  2040.       
  2041.       flvplayback_internal function _createStream() : void
  2042.       {
  2043.          _ns = null;
  2044.          var _loc1_:NetStream = new NetStream(_ncMgr.netConnection);
  2045.          if(_ncMgr.isRTMP)
  2046.          {
  2047.             _loc1_.addEventListener(NetStatusEvent.NET_STATUS,flvplayback_internal::rtmpNetStatus);
  2048.          }
  2049.          else
  2050.          {
  2051.             _loc1_.addEventListener(NetStatusEvent.NET_STATUS,flvplayback_internal::httpNetStatus);
  2052.          }
  2053.          _loc1_.client = createNetStreamClient();
  2054.          _loc1_.bufferTime = _bufferTime;
  2055.          _loc1_.soundTransform = soundTransform;
  2056.          _ns = _loc1_;
  2057.          attachNetStream(_ns);
  2058.       }
  2059.       
  2060.       flvplayback_internal function checkReadyForPlay(param1:uint, param2:uint) : void
  2061.       {
  2062.          var _loc3_:Number = NaN;
  2063.          if(param1 >= param2)
  2064.          {
  2065.             waitingForEnough = false;
  2066.             _cachedState = _state;
  2067.             _state = VideoState.EXEC_QUEUED_CMD;
  2068.             play();
  2069.             execQueuedCmds();
  2070.             return;
  2071.          }
  2072.          if(isNaN(flvplayback_internal::baselineProgressTime))
  2073.          {
  2074.             return;
  2075.          }
  2076.          if(isNaN(totalTime) || totalTime < 0)
  2077.          {
  2078.             waitingForEnough = false;
  2079.             _cachedState = _state;
  2080.             _state = VideoState.EXEC_QUEUED_CMD;
  2081.             play();
  2082.             execQueuedCmds();
  2083.          }
  2084.          else if(flvplayback_internal::totalDownloadTime > 1.5)
  2085.          {
  2086.             _loc3_ = (flvplayback_internal::totalProgressTime - flvplayback_internal::baselineProgressTime) / flvplayback_internal::totalDownloadTime;
  2087.             if(totalTime - playheadTime > (totalTime - flvplayback_internal::totalProgressTime) / _loc3_)
  2088.             {
  2089.                waitingForEnough = false;
  2090.                _cachedState = _state;
  2091.                _state = VideoState.EXEC_QUEUED_CMD;
  2092.                play();
  2093.                execQueuedCmds();
  2094.             }
  2095.          }
  2096.       }
  2097.       
  2098.       flvplayback_internal function closeNS(param1:Boolean = false) : void
  2099.       {
  2100.          if(_ns != null)
  2101.          {
  2102.             if(param1)
  2103.             {
  2104.                doUpdateTime();
  2105.                _currentPos = _ns.time;
  2106.             }
  2107.             flvplayback_internal::_updateTimeTimer.reset();
  2108.             flvplayback_internal::_updateProgressTimer.reset();
  2109.             flvplayback_internal::_idleTimeoutTimer.reset();
  2110.             flvplayback_internal::_autoResizeTimer.reset();
  2111.             flvplayback_internal::_rtmpDoStopAtEndTimer.reset();
  2112.             flvplayback_internal::_rtmpDoSeekTimer.reset();
  2113.             flvplayback_internal::_httpDoSeekTimer.reset();
  2114.             flvplayback_internal::_finishAutoResizeTimer.reset();
  2115.             flvplayback_internal::_delayedBufferingTimer.reset();
  2116.             _ns.removeEventListener(NetStatusEvent.NET_STATUS,flvplayback_internal::rtmpNetStatus);
  2117.             _ns.removeEventListener(NetStatusEvent.NET_STATUS,flvplayback_internal::httpNetStatus);
  2118.             _ns.close();
  2119.             _ns = null;
  2120.          }
  2121.       }
  2122.       
  2123.       public function set playheadUpdateInterval(param1:Number) : void
  2124.       {
  2125.          flvplayback_internal::_updateTimeTimer.delay = param1;
  2126.       }
  2127.       
  2128.       flvplayback_internal function _load(param1:String, param2:Number, param3:Boolean) : void
  2129.       {
  2130.          _prevVideoWidth = super.videoWidth;
  2131.          _prevVideoHeight = super.videoHeight;
  2132.          _autoResizeDone = false;
  2133.          _cachedPlayheadTime = 0;
  2134.          _bufferState = flvplayback_internal::BUFFER_EMPTY;
  2135.          _sawPlayStop = false;
  2136.          _metadata = null;
  2137.          _startingPlay = false;
  2138.          _invalidSeekTime = false;
  2139.          _invalidSeekRecovery = false;
  2140.          _isLive = param3;
  2141.          _contentPath = param1;
  2142.          _currentPos = 0;
  2143.          _streamLength = isNaN(param2) || param2 <= 0 ? Number(NaN) : Number(param2);
  2144.          _atEnd = false;
  2145.          _readyDispatched = false;
  2146.          _lastUpdateTime = NaN;
  2147.          lastUpdateTimeStuckCount = 0;
  2148.          _sawSeekNotify = false;
  2149.          waitingForEnough = false;
  2150.          baselineProgressTime = NaN;
  2151.          startProgressTime = NaN;
  2152.          totalDownloadTime = NaN;
  2153.          totalProgressTime = NaN;
  2154.          _httpDoSeekCount = 0;
  2155.          flvplayback_internal::_updateTimeTimer.reset();
  2156.          flvplayback_internal::_updateProgressTimer.reset();
  2157.          flvplayback_internal::_idleTimeoutTimer.reset();
  2158.          flvplayback_internal::_autoResizeTimer.reset();
  2159.          flvplayback_internal::_rtmpDoStopAtEndTimer.reset();
  2160.          flvplayback_internal::_rtmpDoSeekTimer.reset();
  2161.          flvplayback_internal::_httpDoSeekTimer.reset();
  2162.          flvplayback_internal::_finishAutoResizeTimer.reset();
  2163.          flvplayback_internal::_delayedBufferingTimer.reset();
  2164.          closeNS(false);
  2165.          if(_ncMgr == null)
  2166.          {
  2167.             createINCManager();
  2168.          }
  2169.          var _loc4_:Boolean = _ncMgr.connectToURL(_contentPath);
  2170.          setState(VideoState.LOADING);
  2171.          _cachedState = VideoState.LOADING;
  2172.          if(_loc4_)
  2173.          {
  2174.             _createStream();
  2175.             _setUpStream();
  2176.          }
  2177.          if(!_ncMgr.isRTMP)
  2178.          {
  2179.             flvplayback_internal::_updateProgressTimer.start();
  2180.          }
  2181.       }
  2182.       
  2183.       flvplayback_internal function rtmpDoStopAtEnd(param1:TimerEvent = null) : void
  2184.       {
  2185.          if(flvplayback_internal::_rtmpDoStopAtEndTimer.running)
  2186.          {
  2187.             switch(_state)
  2188.             {
  2189.                case VideoState.DISCONNECTED:
  2190.                case VideoState.CONNECTION_ERROR:
  2191.                   flvplayback_internal::_rtmpDoStopAtEndTimer.reset();
  2192.                   return;
  2193.                default:
  2194.                   if(!(param1 == null || flvplayback_internal::_cachedPlayheadTime == playheadTime))
  2195.                   {
  2196.                      _cachedPlayheadTime = playheadTime;
  2197.                      return;
  2198.                   }
  2199.                   flvplayback_internal::_rtmpDoStopAtEndTimer.reset();
  2200.             }
  2201.          }
  2202.          if(flvplayback_internal::_atEndCheckPlayhead == playheadTime && flvplayback_internal::_atEndCheckPlayhead != flvplayback_internal::_lastSeekTime && !_isLive && playheadTime != 0)
  2203.          {
  2204.             _atEnd = false;
  2205.             _currentPos = 0;
  2206.             _play(0);
  2207.             return;
  2208.          }
  2209.          _atEndCheckPlayhead = NaN;
  2210.          _bufferState = flvplayback_internal::BUFFER_EMPTY;
  2211.          _sawPlayStop = false;
  2212.          _atEnd = true;
  2213.          setState(VideoState.STOPPED);
  2214.          if(_state != VideoState.STOPPED)
  2215.          {
  2216.             return;
  2217.          }
  2218.          doUpdateTime();
  2219.          if(_state != VideoState.STOPPED)
  2220.          {
  2221.             return;
  2222.          }
  2223.          dispatchEvent(new VideoEvent(VideoEvent.COMPLETE,false,false,_state,playheadTime));
  2224.          if(_state != VideoState.STOPPED)
  2225.          {
  2226.             return;
  2227.          }
  2228.          if(_autoRewind && !_isLive && playheadTime != 0)
  2229.          {
  2230.             _atEnd = false;
  2231.             _currentPos = 0;
  2232.             _play(0,0);
  2233.             setState(VideoState.REWINDING);
  2234.          }
  2235.          else
  2236.          {
  2237.             closeNS();
  2238.          }
  2239.       }
  2240.       
  2241.       public function set idleTimeout(param1:Number) : void
  2242.       {
  2243.          flvplayback_internal::_idleTimeoutTimer.delay = param1;
  2244.       }
  2245.       
  2246.       flvplayback_internal function checkEnoughDownloaded(param1:uint, param2:uint) : void
  2247.       {
  2248.          if(param1 == 0 || param2 == uint.MAX_VALUE)
  2249.          {
  2250.             return;
  2251.          }
  2252.          if(isNaN(totalTime) || totalTime <= 0)
  2253.          {
  2254.             if(flvplayback_internal::waitingForEnough && stateResponsive)
  2255.             {
  2256.                waitingForEnough = false;
  2257.                _cachedState = _state;
  2258.                _state = VideoState.EXEC_QUEUED_CMD;
  2259.                play();
  2260.                execQueuedCmds();
  2261.             }
  2262.             return;
  2263.          }
  2264.          if(param1 >= param2)
  2265.          {
  2266.             if(flvplayback_internal::waitingForEnough)
  2267.             {
  2268.                waitingForEnough = false;
  2269.                _cachedState = _state;
  2270.                _state = VideoState.EXEC_QUEUED_CMD;
  2271.                play();
  2272.                execQueuedCmds();
  2273.             }
  2274.             return;
  2275.          }
  2276.          if(isNaN(flvplayback_internal::baselineProgressTime))
  2277.          {
  2278.             baselineProgressTime = param1 / param2 * totalTime;
  2279.          }
  2280.          if(isNaN(flvplayback_internal::startProgressTime))
  2281.          {
  2282.             startProgressTime = getTimer();
  2283.          }
  2284.          else
  2285.          {
  2286.             totalDownloadTime = (getTimer() - flvplayback_internal::startProgressTime) / 1000;
  2287.             totalProgressTime = param1 / param2 * totalTime;
  2288.             if(flvplayback_internal::waitingForEnough)
  2289.             {
  2290.                checkReadyForPlay(param1,param2);
  2291.             }
  2292.          }
  2293.       }
  2294.       
  2295.       public function pause() : void
  2296.       {
  2297.          if(!isXnOK())
  2298.          {
  2299.             if(_state == VideoState.CONNECTION_ERROR || _ncMgr == null || _ncMgr.netConnection == null)
  2300.             {
  2301.                throw new VideoError(VideoError.NO_CONNECTION);
  2302.             }
  2303.             return;
  2304.          }
  2305.          if(_state == VideoState.EXEC_QUEUED_CMD)
  2306.          {
  2307.             _state = flvplayback_internal::_cachedState;
  2308.          }
  2309.          else
  2310.          {
  2311.             if(!stateResponsive)
  2312.             {
  2313.                queueCmd(QueuedCommand.PAUSE);
  2314.                return;
  2315.             }
  2316.             execQueuedCmds();
  2317.          }
  2318.          if(_state == VideoState.PAUSED || _state == VideoState.STOPPED || _ns == null)
  2319.          {
  2320.             return;
  2321.          }
  2322.          _pause(true);
  2323.          setState(VideoState.PAUSED);
  2324.       }
  2325.       
  2326.       public function close() : void
  2327.       {
  2328.          closeNS(true);
  2329.          if(_ncMgr != null && _ncMgr.isRTMP)
  2330.          {
  2331.             _ncMgr.close();
  2332.          }
  2333.          setState(VideoState.DISCONNECTED);
  2334.          dispatchEvent(new VideoEvent(VideoEvent.CLOSE,false,false,_state,playheadTime));
  2335.       }
  2336.       
  2337.       flvplayback_internal function execQueuedCmds() : void
  2338.       {
  2339.          var nextCmd:Object = null;
  2340.          addr163:
  2341.          ┬º┬ºpush(flvplayback_internal::_cmdQueue.length > 0);
  2342.          if(flvplayback_internal::_cmdQueue.length > 0)
  2343.          {
  2344.             while(true)
  2345.             {
  2346.                ┬º┬ºpop();
  2347.                ┬º┬ºpush(stateResponsive || _state == VideoState.DISCONNECTED || _state == VideoState.CONNECTION_ERROR);
  2348.             }
  2349.          }
  2350.          while(┬º┬ºpop() && (flvplayback_internal::_cmdQueue[0].url != null || _state != VideoState.DISCONNECTED && _state != VideoState.CONNECTION_ERROR))
  2351.          {
  2352.             try
  2353.             {
  2354.                nextCmd = flvplayback_internal::_cmdQueue.shift();
  2355.                _cachedState = _state;
  2356.                _state = VideoState.EXEC_QUEUED_CMD;
  2357.                switch(nextCmd.type)
  2358.                {
  2359.                   case QueuedCommand.PLAY:
  2360.                      play(nextCmd.url,nextCmd.time,nextCmd.isLive);
  2361.                      break;
  2362.                   case QueuedCommand.LOAD:
  2363.                      load(nextCmd.url,nextCmd.time,nextCmd.isLive);
  2364.                      break;
  2365.                   case QueuedCommand.PAUSE:
  2366.                      pause();
  2367.                      break;
  2368.                   case QueuedCommand.STOP:
  2369.                      stop();
  2370.                      break;
  2371.                   case QueuedCommand.SEEK:
  2372.                      seek(nextCmd.time);
  2373.                      break;
  2374.                   case QueuedCommand.PLAY_WHEN_ENOUGH:
  2375.                      playWhenEnoughDownloaded();
  2376.                }
  2377.             }
  2378.             finally
  2379.             {
  2380.                if(_state == VideoState.EXEC_QUEUED_CMD)
  2381.                {
  2382.                   _state = flvplayback_internal::_cachedState;
  2383.                }
  2384.             }
  2385.             ┬º┬ºgoto(addr163);
  2386.          }
  2387.       }
  2388.    }
  2389. }
  2390.